package com.foxcai.novel.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import com.foxcai.novel.base.DBConnection;
import com.foxcai.novel.beans.Novel;

public class NovelDao {
	private DBConnection conn = DBConnection.newInstance();

	public Collection query(String strif) {
		Novel novel = null;
		Collection novColl = new ArrayList();
		String sql = "";
		if (strif != null && !strif.equals("")) {
			sql = "select NovId,category,novel,author,NovAcc,comm,UpdTime from novellist where "
					+ strif + "";
		} else {
			sql = "select NovId,category,novel,author,NovAcc,comm,UpdTime from novellist order by NovAcc desc limit 50";
		}
		ResultSet rs = conn.executeQuery(sql);
		try {
			while (rs.next()) {
				novel = new Novel();
				novel.setNovId(rs.getInt("NovId"));
				novel.setNovel(rs.getString("novel"));
				novel.setCategory(rs.getString("category"));
				novel.setAuthor(rs.getString("author"));
				novel.setNovAcc(rs.getInt("novAcc"));
				novel.setComm(rs.getInt("comm"));
				novel.setUpdTime(rs.getString("UpdTime"));
				novColl.add(novel);
			}
		} catch (SQLException ex) {
		}
		conn.close();
		return novColl;
	}
}
